package com.lqy.controller;

import com.lqy.service.Inter.DriverService;
import com.zzg.entity.Driver;
import com.zzg.util.UuidUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lqy
 * @version 1.0.0
 * @ClassName：DriverController
 * @Description: 车辆管理控制器
 * @date 2021/6/21
 **/
@Controller
public class DriverController {
    /**
     * 车辆管理接口类
     */
    @Resource
    private DriverService driverService;

    @RequestMapping("/getAllDriver.action")
    @ResponseBody
    public Map<String,Object> getAllDriver(int page, int limit){
        Map<String,Object> map=new HashMap<>();

        List<Driver> driverList=driverService.getDriver();

        List<Driver> drivers=driverService.getCouByPage(page,limit);

        map.put("code","0");
        map.put("msg","0");
        map.put("count",driverList.size());
        map.put("data",drivers);

        return map;
    }

    @RequestMapping("/insertDriver.action")
    @ResponseBody
    public int insertDriver(Driver driver){

        driver.setDriverId(UuidUtil.getUuid());

        int i = driverService.insertDriver(driver);

        return i;
    }

    @RequestMapping("/deleteDriver.action")
    public void deleteDriver(String driverId){

        driverService.deleteDriver(driverId);

    }

    @RequestMapping(value = "/getDriverById.action",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Driver getDriverById(String driverId){

        Driver userById = driverService.getUserById(driverId);

        return userById;
    }

    @RequestMapping("/updateDriver.action")
    @ResponseBody
    public void updateDriver(Driver driver){

        driverService.updateDriver(driver);

    }

    @RequestMapping(value = "/getAllDrivers.action",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getAllDrivers(Driver drivers){

        Map<String,Object> map=new HashMap<>();

        List<Driver> driverList=driverService.getDrivers(drivers);

        map.put("code","0");
        map.put("msg","0");
        map.put("count",driverList.size());
        map.put("data",driverList);

        return map;
    }


}
